import request from '@/sheep/request';
import {
	baseUrl,
	apiPath,

} from '@/sheep/config';
const bankAcountApi = {
	/**
	 * 查询银行卡列表
	 */
	getBankCardList: (data) => {
		return request({
			url: '/card/getBankCardList',
			method: 'POST',
			data
		});
	},
	/**
	 * 个人用户新增绑卡申请
	 */
	bindcardApply: (data) => {
		return request({
			url: '/card/individual-bindcard-apply',
			method: 'POST',
			data
		});
	},
	/**
	 * 获取密码因子
	 */
	getAcctmgrRandom: (data) => {
		return request({
			url: '/pay/acctmgr/get-random',
			method: 'POST',
			data
		});
	},
	/**
	 * 获取密码控件token
	 */
	getAcctmgrPasswordToken: (data) => {
		return request({
			url: '/pay/acctmgr/apply-password-element',
			method: 'POST',
			data
		});
	},
	/**
	 * 个人用户新增绑卡验证
	 */
	bindcardVerify: (data) => {
		return request({
			url: '/card/individual-bindcard-verify',
			method: 'POST',
			data
		});
	},
	/**
	 *个人用户解绑银行卡
	 */
	unlinkedacct: (data) => {
		return request({
			url: '/card/unlinkedacct-ind-apply',
			method: 'POST',
			data
		});
	},
	//--------------开户------------------------

	/**
	 * 绑定手机验证码申请
	 */
	regphoneVerifycodeApply: (data) => {
		return request({
			url: '/pay/acctmgr/regphone-verifycode-apply',
			method: 'POST',
			data
		});
	},
	/**
	 * 绑定手机验证码验证
	 */
	regphoneVerifycodeVerify: (data) => {
		return request({
			url: '/pay/acctmgr/regphone-verifycode-verify',
			method: 'POST',
			data
		});
	},
	/**
	 * 开户申请
	 */
	openacctApply: (data) => {
		return request({
			url: '/pay/acctmgr/openacct-apply-individual',
			method: 'POST',
			data
		});
	},
	/**
	 * 开户验证
	 */
	openacctVerify: (data) => {
		return request({
			url: '/pay/acctmgr/openacct-verify-individual',
			method: 'POST',
			data
		});
	},
	// 上传身份证照片
	uploadIdCard: (fileObj, bankInfo) => {
		console.log('上传身份证照片：', fileObj, bankInfo);
		console.log(fileObj.file)
		const token = uni.getStorageSync('token') || '';
		uni.showLoading({
			title: '上传中',
		});
		return new Promise((resolve, reject) => {
			const files = [{
				name: 'file', // 可选，默认为 "file"
				uri: fileObj.path // 文件的本地地址，必需
			}];
			console.log("正在走上传")
			uni.uploadFile({
				url: baseUrl + apiPath + '/pay/acctmgr/fileUpload',
				files: files,
				// file: fileObj.file, //h5网页上传
				name: 'file',
				formData: {
					'phone': bankInfo.bindPhone,
					'userId': uni.getStorageSync('userId') || '',
					'fileType': fileObj.extname,
				},
				header: {
					// Accept: 'text/json',
					Accept: '*/*',

					Authorization: token,
				},
				success: (uploadFileRes) => {
					console.log('上传成功', uploadFileRes)
					let result = JSON.parse(uploadFileRes.data);
					if (result.error === 1) {
						uni.showToast({
							icon: 'none',
							title: result.msg,
						});
					} else {
						return resolve(result);
					}
				},
				fail: (error) => {
					console.log('上传失败：', error);
					return resolve(false);
				},
				complete: () => {
					uni.hideLoading();
				},
			});
		});
	},

};

export default bankAcountApi;